package com.itheima.tilas.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.tilas.Utils.ResultUtil;
import com.itheima.tilas.config.StudentConfig;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 132
 */
@RestController
@RequestMapping("yml")
public class TestReadYamlController {

    @Value("${student.name}")
    String name;
    @Value("${student.age}")
    String age;
    @Value("${student.subject}")
    String[] subject;
    @Value("${student.teachers[0]}")
    List<String> teachers;
    @Resource
    StudentConfig studentConfig;

    @GetMapping
    public ResultUtil readCustomConfigByYml(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name",studentConfig.getName());
        jsonObject.put("age",studentConfig.getAge());
        jsonObject.put("科目",studentConfig.getSubject());
        jsonObject.put("学科",studentConfig.getTeachers());
        jsonObject.put("家庭成员",studentConfig.getFamily());
        return ResultUtil.success(jsonObject);
    }
}
